#!/usr/bin/env python3
# _*_coding:utf-8 _*_
__author__ = "Gao"
from django import forms
from django.forms import fields
from django.forms import widgets
from django.forms import ValidationError

class PasswordResetForm(forms.Form):
    '''修改密码form验证'''
    password1 = fields.CharField(
        widget=widgets.PasswordInput(attrs={'class': "form-control",'placeholder': '请输入密码'}),
        required=True,
        min_length=4,
        error_messages={'required': '密码不能为空!', 'min_length': '密码最少为4个字符'},
        label='密码:'
    )

    password2 = fields.CharField(
        widget=widgets.PasswordInput(attrs={'class': "form-control",'placeholder': '请重新输入密码'}),
        required=True,
        min_length=4,
        error_messages={'required': '密码不能为空!','min_length': '密码最少为4个字符'},
        label='密码(重复):'
    )

    def clean(self):
        if self.cleaned_data.get('password1') and self.cleaned_data.get('password2'):
            if self.cleaned_data.get('password1').strip() == self.cleaned_data.get('password2') != '':
                return self.cleaned_data
        raise ValidationError('两次输入密码不一致')
